package com.quanxi.qxaimain.common.util.RestTemplateUtils;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author lyx
 * @create 2021/4/15 15:41
 */
public class Demotest {




    @Test
    public  void get1(){
   String url="http://127.0.0.1:6812/qxzsk/indicators/downloadExcel?ind_id=c8&D1=2020-1-01 00:00:00&D2=2020-5-01 00:00:00&sql=select *  from TB_CIS_DRADVICE_DETAIL where rownum<10";

        ResponseEntity<JSONObject> jsonObjectResponseEntity = RestTemplateUtils.get(url, JSONObject.class);
        System.out.println(jsonObjectResponseEntity);


    }


    /**
     * 测试普通表单参数的POST请求
     */
    @Test
    public void one() {
        String url = "http://192.168.66.182:6812/qxzsk/indicators/sqlDataSet";
        MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
        requestBody.add("ind_id", "测试");
        requestBody.add("D1", "2020-1-01 00:00:00");
        requestBody.add("D2", "2020-5-01 00:00:00");
        requestBody.add("flag", 0);
        ResponseEntity<JSONObject> response = RestTemplateUtils.post(url, requestBody, JSONObject.class);
        System.out.println(response.getStatusCode());
        System.out.println(response.getBody());
    }

    /**
     * 测试JSON格式请求体Body方式POST请求
     */
    @Test
    public void two() {
        String url = "http://192.168.66.182:6812/qxzsk/indicators/sqlDataSetList";
        JSONObject requestBody = new JSONObject();
        List<String> list =new ArrayList<>();
         list.add("nn3202");
        requestBody.put("indIdList", list);
        requestBody.put("startTime", "2020-01-01 00:00:00");
        requestBody.put("endTime", "2020-04-01 00:00:00");
        requestBody.put("mqFlag",false);
        ResponseEntity<JSONObject> response = RestTemplateUtils.post(url, requestBody, JSONObject.class);

        System.out.println(response.getStatusCode());
        System.out.println(response.getBody());
    }
    @Test
    public  void ttt(){
        String url = "http://192.168.66.182:6812/qxzsk/indicators/sqlDataSetList";
        List<String> indIdList=new ArrayList<>();
        indIdList.add("nn3202");
        JSONObject requestBody = new JSONObject();
        requestBody.put("indIdList",indIdList);
        requestBody.put("startTime","2020-01-01 00:00:00");
        requestBody.put("endTime","2020-04-01 00:00:00");
        requestBody.put("mqFlag",false);
        ResponseEntity<String> post = RestTemplateUtils.post(url, requestBody, String.class);
        ResponseEntity<JSONObject> post1 = RestTemplateUtils.post(url, requestBody, JSONObject.class);
        String body = post.getBody();
        System.out.println(JSONObject.parseObject(body).get("ttt"));



    }




    @Test
    public void 龙岗门诊病历接口() {
        String url = "http://192.168.66.182:6800/qxzsk/emrsplit/outpatient";
        JSONObject requestBody = new JSONObject();
        List<String> list =new ArrayList<>();
        list.add("fc9f63c69bcc486db6d0fb48da6cf2dc");

        //参数
        long starttime=System.currentTimeMillis();
        requestBody.put("emrid", list);
        requestBody.put("emrtype", "m11");
        requestBody.put("hospital", "LG2Y");
        ResponseEntity<JSONObject> response = RestTemplateUtils.post(url, requestBody, JSONObject.class);
        long endtime=System.currentTimeMillis();
        System.out.println("====================================================");
        System.out.println((endtime - starttime)+"ms");
        System.out.println(response.getStatusCode());
        System.out.println(response.getBody());
    }


}